home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2 Examples.sit / Raven 1.2 Examples / Quill / Source / ViewCommands.h < prev    next >
Text File  |  1997-07-28  |  13KB  |  569 lines

  1. /*
  2.  *  File:       ViewCommands.h
  3.  *  Summary:       Command objects for manipulating views.
  4.  *  Written by: Jesse Jones
  5.  *
  6.  *  Copyright ゥ 1996 Jesse Jones. 
  7.  *    For conditions of distribution and use, see copyright notice in ZTypes.h  
  8.  *
  9.  *  Change History (most recent first):    
  10.  *
  11.  *         <->     8/29/96    JDJ        Created
  12.  */
  13.  
  14. #pragma once
  15.  
  16. #include <ZGeometry.h>
  17. #include <ZHandle.h>
  18. #include <ZUndoableCommand.h>
  19. #include <ZView.h>
  20.  
  21.  
  22. //-----------------------------------
  23. //    Forward References
  24. //
  25. class CViewContainer;
  26. class TPane;
  27. class TView;
  28.  
  29. template<class TYPE, class ALLOCATOR> class list;
  30.  
  31.  
  32. // ===================================================================================
  33. //    class CResizePaneCommand
  34. // ===================================================================================
  35. class CResizePaneCommand : public TUndoableCommand {
  36.  
  37.     typedef TUndoableCommand Inherited;
  38.  
  39. //-----------------------------------
  40. //    Initialization/Destruction
  41. //
  42. public:
  43.     virtual             ~CResizePaneCommand();
  44.     
  45.                         CResizePaneCommand(TPane* pane, const TRect& newFrame);
  46.     
  47.                         CResizePaneCommand(TPane* pane, const TRect& oldFrame, const TRect& newFrame);
  48.     
  49. //-----------------------------------
  50. //    Inherited API
  51. //
  52. public:
  53.     virtual string        GetText() const;
  54.  
  55.     virtual bool         IsValid() const;
  56.  
  57. protected:
  58.     virtual void         OnDo();
  59.  
  60.     virtual void         OnUndo();
  61.  
  62.     virtual void         OnRedo();
  63.             
  64. //-----------------------------------
  65. //    Member data
  66. //
  67. protected:
  68.     CViewContainer*    mContainer;
  69.     TSafePtr<TPane>    mPane;
  70.     TRect            mOldFrame;
  71.     TRect            mNewFrame;
  72. };
  73.  
  74.  
  75. // ===================================================================================
  76. //    class CPaneEditCommand
  77. // ===================================================================================
  78. class CPaneEditCommand : public TUndoableCommand {
  79.  
  80.     typedef TUndoableCommand Inherited;
  81.  
  82. //-----------------------------------
  83. //    Initialization/Destruction
  84. //
  85. public:
  86.     virtual             ~CPaneEditCommand();
  87.     
  88.                         CPaneEditCommand(CViewContainer* container, bool addSelection = true);
  89.         
  90.                         CPaneEditCommand(CViewContainer* container, TUndoMgr* context, bool addSelection = true);
  91.  
  92. //-----------------------------------
  93. //    Inherited API
  94. //
  95. public:
  96.     virtual bool         IsValid() const;
  97.  
  98. //-----------------------------------
  99. //    Types
  100. //
  101. protected:
  102.     struct SInfo {
  103.         TSafePtr<TPane>    pane;
  104.         TSafePtr<TView>    super;
  105.         SPaneInfo        oldInfo;
  106.         SPaneInfo        newInfo;
  107.  
  108.                         SInfo() : pane(nil), super(nil)            {}
  109.                             
  110.                         SInfo(TPane* subPane) : pane(subPane), super(pane->GetSuperView())    {oldInfo = newInfo = pane->GetInfo();}
  111.                             
  112.             bool         operator==(const SInfo& rhs) const        {return pane == rhs.pane;}
  113.  
  114.             bool         operator<(const SInfo& rhs) const        {return pane < rhs.pane;}
  115.                         // ・・ Should not be neccessary.
  116.  
  117.             bool         operator!=(const SInfo& rhs) const        {return pane != rhs.pane;}
  118.     };        
  119.  
  120. //-----------------------------------
  121. //    Member data
  122. //
  123. protected:
  124.     CViewContainer*    mContainer;
  125.     
  126.     list<SInfo, allocator<SInfo> >*    mPanes;
  127. };
  128.  
  129.  
  130. // ===================================================================================
  131. //    class CAddPanesCommand
  132. // ===================================================================================
  133. class CAddPanesCommand : public CPaneEditCommand {
  134.  
  135.     typedef CPaneEditCommand Inherited;
  136.  
  137. //-----------------------------------
  138. //    Initialization/Destruction
  139. //
  140. public:
  141.     virtual             ~CAddPanesCommand() = 0;
  142.     
  143.                         CAddPanesCommand(CViewContainer* container, bool addSelection = true);
  144.         
  145.                         CAddPanesCommand(CViewContainer* container, TUndoMgr* context, bool addSelection = true);
  146.         
  147. //-----------------------------------
  148. //    New API
  149. //
  150. protected:
  151.     virtual void         OnAdd();
  152.  
  153.     virtual void         OnRemove();
  154. };
  155.  
  156.  
  157. // ===================================================================================
  158. //    class CAddSubPanesCommand
  159. // ===================================================================================
  160. class CAddSubPanesCommand : public CAddPanesCommand {
  161.  
  162.     typedef CAddPanesCommand Inherited;
  163.  
  164. //-----------------------------------
  165. //    Initialization/Destruction
  166. //
  167. public:
  168.     virtual             ~CAddSubPanesCommand();
  169.     
  170.                         CAddSubPanesCommand(CViewContainer* container, TView* super, TUndoMgr* context);
  171.         
  172. //-----------------------------------
  173. //    New API
  174. //
  175. public:
  176.             void         AddPane(TPane* newPane);
  177.         
  178. //-----------------------------------
  179. //    Inherited API
  180. //
  181. public:
  182.     virtual string        GetText() const;
  183.  
  184. protected:
  185.     virtual void         OnDo();
  186.  
  187.     virtual void         OnUndo();
  188.  
  189.     virtual void         OnRedo();
  190.             
  191. //-----------------------------------
  192. //    Member data
  193. //
  194. protected:
  195.     TView*        mSuper;
  196. };
  197.  
  198.  
  199. // ===================================================================================
  200. //    class CDeletePanesCommand
  201. // ===================================================================================
  202. class CDeletePanesCommand : public CAddPanesCommand {
  203.  
  204.     typedef CAddPanesCommand Inherited;
  205.  
  206. //-----------------------------------
  207. //    Initialization/Destruction
  208. //
  209. public:
  210.     virtual             ~CDeletePanesCommand();
  211.     
  212.                         CDeletePanesCommand(CViewContainer* container);
  213.         
  214. //-----------------------------------
  215. //    Inherited API
  216. //
  217. public:
  218.     virtual string        GetText() const;
  219.  
  220. protected:
  221.     virtual void         OnDo();
  222.  
  223.     virtual void         OnUndo();
  224.  
  225.     virtual void         OnRedo();
  226. };
  227.  
  228.  
  229. // ===================================================================================
  230. //    class CDuplicatePanesCommand
  231. // ===================================================================================
  232. class CDuplicatePanesCommand : public CAddPanesCommand {
  233.  
  234.     typedef CAddPanesCommand Inherited;
  235.  
  236. //-----------------------------------
  237. //    Initialization/Destruction
  238. //
  239. public:
  240.     virtual             ~CDuplicatePanesCommand();
  241.     
  242.                         CDuplicatePanesCommand(CViewContainer* container);
  243.         
  244. //-----------------------------------
  245. //    Inherited API
  246. //
  247. public:
  248.     virtual string        GetText() const;
  249.  
  250. protected:
  251.     virtual void         OnDo();
  252.  
  253.     virtual void         OnUndo();
  254.  
  255.     virtual void         OnRedo();
  256. };
  257.  
  258.  
  259. // ===================================================================================
  260. //    class CMovePanesCommand
  261. // ===================================================================================
  262. class CMovePanesCommand : public CPaneEditCommand {
  263.  
  264.     typedef CPaneEditCommand Inherited;
  265.  
  266. //-----------------------------------
  267. //    Initialization/Destruction
  268. //
  269. public:
  270.     virtual             ~CMovePanesCommand();
  271.         
  272.                         CMovePanesCommand(CViewContainer* container, TView* super, TUndoMgr* context);
  273.         
  274. //-----------------------------------
  275. //    New API
  276. //
  277. public:
  278.             void         AddPane(TPane* newPane, const TPoint& newLoc);
  279.         
  280. //-----------------------------------
  281. //    Inherited API
  282. //
  283. public:
  284.     virtual string        GetText() const;
  285.             
  286. protected:
  287.     virtual void         OnDo();
  288.  
  289.     virtual void         OnUndo();
  290.  
  291.     virtual void         OnRedo();
  292.  
  293. //-----------------------------------
  294. //    Member data
  295. //
  296. protected:
  297.     TView*        mNewSuper;
  298. };
  299.  
  300.  
  301. // ===================================================================================
  302. //    class CCopyPanesCommand
  303. // ===================================================================================
  304. class CCopyPanesCommand : public CAddPanesCommand {
  305.  
  306.     typedef CAddPanesCommand Inherited;
  307.  
  308. //-----------------------------------
  309. //    Initialization/Destruction
  310. //
  311. public:
  312.     virtual             ~CCopyPanesCommand();
  313.     
  314.                         CCopyPanesCommand(CViewContainer* container);
  315.         
  316. //-----------------------------------
  317. //    Inherited API
  318. //
  319. public:
  320.     virtual string        GetText() const;
  321.  
  322. protected:
  323.     virtual void         OnDo();
  324.  
  325.     virtual void         OnUndo();
  326.  
  327.     virtual void         OnRedo();
  328.             
  329. //-----------------------------------
  330. //    Member data
  331. //
  332. protected:
  333.     THandle        mOldScrap;
  334.     THandle        mNewScrap;
  335. };
  336.  
  337.  
  338. // ===================================================================================
  339. //    class CCutPanesCommand
  340. // ===================================================================================
  341. class CCutPanesCommand : public CCopyPanesCommand {
  342.  
  343.     typedef CCopyPanesCommand Inherited;
  344.  
  345. //-----------------------------------
  346. //    Initialization/Destruction
  347. //
  348. public:
  349.     virtual             ~CCutPanesCommand();
  350.     
  351.                         CCutPanesCommand(CViewContainer* container);
  352.         
  353. //-----------------------------------
  354. //    Inherited API
  355. //
  356. public:
  357.     virtual string        GetText() const;
  358.  
  359. protected:
  360.     virtual void         OnDo();
  361.  
  362.     virtual void         OnUndo();
  363.  
  364.     virtual void         OnRedo();
  365. };
  366.  
  367.  
  368. // ===================================================================================
  369. //    class CPastePanesCommand
  370. // ===================================================================================
  371. class CPastePanesCommand : public CAddPanesCommand {
  372.  
  373.     typedef CAddPanesCommand Inherited;
  374.  
  375. //-----------------------------------
  376. //    Initialization/Destruction
  377. //
  378. public:
  379.     virtual             ~CPastePanesCommand();
  380.     
  381.                         CPastePanesCommand(CViewContainer* container, TView* superView);
  382.         
  383. //-----------------------------------
  384. //    Inherited API
  385. //
  386. public:
  387.     virtual string        GetText() const;
  388.  
  389. protected:
  390.     virtual void         OnDo();
  391.  
  392.     virtual void         OnUndo();
  393.  
  394.     virtual void         OnRedo();
  395.             
  396. //-----------------------------------
  397. //    Member data
  398. //
  399. protected:
  400.     TView*            mSuper;
  401. };
  402.  
  403.  
  404. // ===================================================================================
  405. //    class COffsetPanesCommand
  406. // ===================================================================================
  407. class COffsetPanesCommand : public CPaneEditCommand {
  408.  
  409.     typedef CPaneEditCommand Inherited;
  410.  
  411. //-----------------------------------
  412. //    Initialization/Destruction
  413. //
  414. public:
  415.     virtual             ~COffsetPanesCommand() = 0;
  416.     
  417.                         COffsetPanesCommand(CViewContainer* container);
  418.         
  419. //-----------------------------------
  420. //    Inherited API
  421. //
  422. protected:
  423.     virtual void         OnDo();
  424.  
  425.     virtual void         OnUndo();
  426.  
  427.     virtual void         OnRedo();
  428. };
  429.  
  430.  
  431. // ===================================================================================
  432. //    class CNudgePaneCommand
  433. // ===================================================================================
  434. class CNudgePaneCommand : public COffsetPanesCommand {
  435.  
  436.     typedef COffsetPanesCommand Inherited;
  437.  
  438. //-----------------------------------
  439. //    Initialization/Destruction
  440. //
  441. public:
  442.     virtual             ~CNudgePaneCommand();
  443.     
  444.                         CNudgePaneCommand(CViewContainer* container, char key);
  445.                         // key should be one of the arrow keys
  446.         
  447. //-----------------------------------
  448. //    New API
  449. //
  450. public:
  451.     virtual bool         CanNudge(CViewContainer* container, char key) const;
  452.  
  453.     virtual void         Nudge();
  454.  
  455. //-----------------------------------
  456. //    Inherited API
  457. //
  458. public:
  459.     virtual string        GetText() const;
  460.  
  461. protected:
  462.     virtual void         OnDo();
  463.  
  464.     virtual void         OnUndo();
  465.  
  466.     virtual void         OnRedo();
  467.             
  468. //-----------------------------------
  469. //    Member data
  470. //
  471. protected:
  472.     char     mKey;    
  473.     bool    mExecuted;
  474. };
  475.  
  476.  
  477. // ===================================================================================
  478. //    class CAlignLeftCommand
  479. // ===================================================================================
  480. class CAlignLeftCommand : public COffsetPanesCommand {
  481.  
  482.     typedef COffsetPanesCommand Inherited;
  483.  
  484. //-----------------------------------
  485. //    Initialization/Destruction
  486. //
  487. public:
  488.     virtual             ~CAlignLeftCommand();
  489.     
  490.                         CAlignLeftCommand(CViewContainer* container);
  491.         
  492. //-----------------------------------
  493. //    Inherited API
  494. //
  495. public:
  496.     virtual string        GetText() const;
  497. };
  498.  
  499.  
  500. // ===================================================================================
  501. //    class CAlignRightCommand
  502. // ===================================================================================
  503. class CAlignRightCommand : public COffsetPanesCommand {
  504.  
  505.     typedef COffsetPanesCommand Inherited;
  506.  
  507. //-----------------------------------
  508. //    Initialization/Destruction
  509. //
  510. public:
  511.     virtual             ~CAlignRightCommand();
  512.     
  513.                         CAlignRightCommand(CViewContainer* container);
  514.         
  515. //-----------------------------------
  516. //    Inherited API
  517. //
  518. public:
  519.     virtual string        GetText() const;
  520. };
  521.  
  522.  
  523. // ===================================================================================
  524. //    class CAlignTopCommand
  525. // ===================================================================================
  526. class CAlignTopCommand : public COffsetPanesCommand {
  527.  
  528.     typedef COffsetPanesCommand Inherited;
  529.  
  530. //-----------------------------------
  531. //    Initialization/Destruction
  532. //
  533. public:
  534.     virtual             ~CAlignTopCommand();
  535.     
  536.                         CAlignTopCommand(CViewContainer* container);
  537.         
  538. //-----------------------------------
  539. //    Inherited API
  540. //
  541. public:
  542.     virtual string        GetText() const;
  543. };
  544.  
  545.  
  546. // ===================================================================================
  547. //    class CAlignBottomCommand
  548. // ===================================================================================
  549. class CAlignBottomCommand : public COffsetPanesCommand {
  550.  
  551.     typedef COffsetPanesCommand Inherited;
  552.  
  553. //-----------------------------------
  554. //    Initialization/Destruction
  555. //
  556. public:
  557.     virtual             ~CAlignBottomCommand();
  558.     
  559.                         CAlignBottomCommand(CViewContainer* container);
  560.         
  561. //-----------------------------------
  562. //    Inherited API
  563. //
  564. public:
  565.     virtual string        GetText() const;
  566. };
  567.  
  568.  
  569.